<template>
  <div>
    <c-table
      :table-column="normalTableColumn"
      @on-save="onSaveDJ"
      @uploadReportFile1="uploadReportFileDJ"
      :table-data="list"
      :operation="true"
      @serial="preAcceptanceHandle"
      @preAcceptance="preAcceptanceHandle"
      v-if="billType === 'NORMAL'"
      :isDelete="false"
    ></c-table>
    <c-table
      :table-column="systemTableColumn"
      @on-save="onSave"
      @uploadReportFile1="uploadReportFile1"
      @uploadReportFile2="uploadReportFile2"
      @on-delete="onDelete"
      :operation="true"
      :table-data="list"
      v-else
    ></c-table>
    <AcceptanceDialog
      v-if="showDetailDialog"
      :detailData="detailData"
      @close="closeHandle"
    ></AcceptanceDialog>
  </div>
</template>

<script>
import { acceptanceList } from "@/utils/const.js";
import AcceptanceDialog from "./AcceptanceDialog.vue";
import acceptanceApi from "@/apis/overview/acceptance.js";
export default {
  components: { AcceptanceDialog },
  props: {
    billType: {
      // NORMAL: 设备库, SYSTEM: 系统库
      type: String,
      default: "NORMAL",
    },
    list: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      normalTableColumn: {
        deviceCode: {
          label: "单机代号",
          columnProp: {
            align: "center",
          },
        },
        deviceName: {
          label: "单机名称",
          columnProp: {
            align: "center",
          },
        },
        designOrg: {
          label: "设计单位",
          columnProp: {
            align: "center",
          },
        },
        productionOrg: {
          label: "生产单位",
          columnProp: {
            align: "center",
          },
        },
        matchOrg: {
          label: "齐套单位",
          columnProp: {
            align: "center",
          },
        },
        deviceNos: {
          type: "link",
          label: "设备编号",
          text: "",
          columnProp: {
            align: "center",
          },
        },
        preAcceptance: {
          type: "link",
          label: "预验收",
          text: "详情",
          columnProp: {
            align: "center",
          },
        },
        qualified: {
          type: "select",
          selectOption: JSON.parse(JSON.stringify(acceptanceList)),
          label: "验收合格",
          columnProp: {
            align: "center",
          },
        },
        acceptance: {
          type: "upload-btn1",
          label: "验收",
          columnProp: {
            align: "center",
          },
        },
      },
      systemTableColumn: {
        sysCode: {
          label: "系统代号",
          columnProp: {
            align: "center",
          },
        },
        sysName: {
          label: "系统名称",
          columnProp: {
            align: "center",
          },
        },
        designOrg: {
          type: "input",
          label: "设计单位",
          columnProp: {
            align: "center",
          },
        },
        productionOrg: {
          type: "input",
          label: "生产单位",
          columnProp: {
            align: "center",
          },
        },
        matchOrg: {
          type: "input",
          label: "齐套单位",
          columnProp: {
            align: "center",
          },
        },
        sysNo: {
          label: "系统编号",
          columnProp: {
            align: "center",
          },
        },
        qualified: {
          type: "select",
          selectOption: JSON.parse(JSON.stringify(acceptanceList)),
          label: "验收合格",
          columnProp: {
            align: "center",
          },
        },
        reportAttachId: {
          type: "upload-btn1",
          label: "报告",
          columnProp: {
            align: "center",
          },
        },
        resAttachId: {
          type: "upload-btn2",
          label: "结论",
          columnProp: {
            align: "center",
          },
        },
      },
      showDetailDialog: false,
      detailData: [], //弹窗
    };
  },
  watch: {
    billType(val) {},
  },
  methods: {
    onSave(row) {
      row.edit = false;
      this.$emit("saveRow", row);
    },
    onSaveDJ(row) {
      row.edit = false;
      this.$emit("saveRow", row, "DJ");
    },
    uploadReportFile1(e) {
      let row = e.row;
      row.reportAttachId = e.fileData.id;
      this.$emit("saveRow", row);
    },
    uploadReportFileDJ(e) {
      let row = e.row;
      row.psjlAttachId = e.fileData.id;
      this.$emit("saveRow", row, "DJ");
    },
    uploadReportFile2(e) {
      let row = e.row;
      row.resAttachId = e.fileData.id;
      this.$emit("saveRow", row);
    },
    onDelete(row) {
      this.$emit("deleteRow", row);
    },
    // 查看详情
    preAcceptanceHandle(row) {
      this.showDetailDialog = true;
      // 获取编号
      acceptanceApi
        .queryBH({
          deviceId: row.id,
        })
        .then(({ data }) => {
          this.detailData = data;
        });
    },
    closeHandle() {
      this.showDetailDialog = false;
    },
  },
};
</script>

<style>
</style>